package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.FArray;
import com.fr.util.Utils;
import java.util.Iterator;

public class JOINARRAY extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    if (!(paramArrayOfObject[0] instanceof FArray))
      return paramArrayOfObject[0];
    StringBuffer localStringBuffer = new StringBuffer();
    Iterator localIterator = ((FArray)paramArrayOfObject[0]).iterator();
    String str = Utils.objectToString((paramArrayOfObject.length > 1) ? paramArrayOfObject[1] : "");
    while (true)
    {
      do
      {
        if (!(localIterator.hasNext()))
          break label99;
        localStringBuffer.append(localIterator.next());
      }
      while (!(localIterator.hasNext()));
      localStringBuffer.append(str);
    }
    label99: return localStringBuffer.toString();
  }

  public Function.Type getType()
  {
    return Function.ARRAY;
  }

  public String getCN()
  {
    return "JOINARRAY(array,sepa):返回一个由sepa作为分隔符的字符串.\narray:[arg1,arg2...]格式的数组;\nsepa:分隔符。\n示例:\nJOINARRAY([1,2],\";\") = [1;2].\nJOINARRAY([hello,world],\"-\") = [hello-world].";
  }

  public String getEN()
  {
    return "JOINARRAY(array,separator):return an array with sepa as the separator.\narray:array of [arg1,arg2...] type;\nsepa:separator.\nExamples:\nJOINARRAY([1,2],\";\") = [1;2].\nJOINARRAY([hello,world],\"-\") = [hello-world].";
  }
}